home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / UNIXTOOL / MEMACS / Asm / EmacsKeys
Text File  |  1990-07-29  |  6KB  |  272 lines

  1. ;    Keyboard Handler Module for MicroEMACS 3.10e
  2. ;
  3. ;    Recognises Archimedes keypresses, and generates a distinct
  4. ;    input buffer character (or set thereof) for each possible
  5. ;    combination.
  6. ;
  7.  
  8. ;    History
  9. ;    -------
  10. ;
  11. ;    Original    Set up as a relocatable module, installed from
  12. ;            Emacs, in TTinit().
  13. ;
  14. ;    14/04/91    Converted to relocatable code, linked with Emacs
  15.  
  16. ; Register declarations
  17.  
  18. R0    RN    0
  19. R1    RN    1
  20. R2    RN    2
  21. R3    RN    3
  22. R4    RN    4
  23. R5    RN    5
  24. R6    RN    6
  25. R7    RN    7
  26. R8    RN    8
  27. R9    RN    9
  28. R10    RN    10
  29. R11    RN    11
  30. R12    RN    12
  31. R13    RN    13
  32. R14    RN    14
  33. R15    RN    15
  34.  
  35. r0    RN    0
  36. r1    RN    1
  37. r2    RN    2
  38. r3    RN    3
  39. r4    RN    4
  40. r5    RN    5
  41. r6    RN    6
  42. r7    RN    7
  43. r8    RN    8
  44. r9    RN    9
  45. r10    RN    10
  46. r11    RN    11
  47. r12    RN    12
  48. r13    RN    13
  49. r14    RN    14
  50. r15    RN    15
  51.  
  52. wr    RN    12
  53. sp    RN    13
  54. lr    RN    14
  55. pc    RN    15
  56.  
  57. ; PC flags
  58.  
  59. Overflow    *    &10000000
  60. Carry        *    &20000000
  61. Zero        *    &40000000
  62. Negative    *    &80000000
  63. USR_Mode    *    &00000003
  64.  
  65. ; SWI numbers
  66.  
  67. OS_CallAVector    *    &00020034
  68.  
  69. ; Vector numbers
  70.  
  71. InsV        *    &14
  72. EventV        *    &10
  73.  
  74. ; Event numbers
  75.  
  76. KeyPress    *    &0B
  77.  
  78. ; Keyboard Codes
  79.  
  80. LShift        *    &4C
  81. RShift        *    &58
  82. LCtrl        *    &3B
  83. RCtrl        *    &61
  84. LAlt        *    &5E
  85. RAlt        *    &60
  86.  
  87. Delete        *    &34
  88. Home        *    &20
  89. PageDown    *    &36
  90. PageUp        *    &21
  91. Backspace    *    &1E
  92. Return        *    &47
  93. Enter        *    &67
  94.  
  95. ; New buffer codes for non-standard keys
  96.  
  97. NewDelete    *    &C0
  98. NewHome        *    &C1
  99. NewPageDown    *    &C2
  100. NewPageUp    *    &C3
  101. NewBackspace    *    &C4
  102. NewReturn    *    &C5
  103. NewEnter    *    &C6
  104.  
  105. Alt_Prefix    *    &7F
  106.  
  107. ; Service call numbers
  108.  
  109.     AREA    |Asm$$code|, CODE, READONLY
  110.  
  111.     EXPORT    Event_Handler
  112.     EXPORT    Insert_Handler
  113.  
  114. ; This is our event handler for the keypress event. It keeps track of the
  115. ; last key pressed, and also the shift status of the various "shifting"
  116. ; keys (ie Shift, Ctrl and Alt).
  117.  
  118. Event_Handler
  119.     CMP    R0,#KeyPress        ; Is it our event?
  120.     MOVNES    pc,lr            ; If not, quit
  121.  
  122.     STR    R2,Vector_Key        ; Save the last key pressed
  123.  
  124.     CMP    R2,#LShift        ; Check for Shift keys
  125.     CMPNE    R2,#RShift
  126.     STREQ    R1,Vector_Shift        ; Save Shift status
  127.  
  128.     CMP    R2,#LCtrl        ; Check for Control keys
  129.     CMPNE    R2,#RCtrl
  130.     STREQ    R1,Vector_Ctrl        ; Save Control status
  131.  
  132.     CMP    R2,#LAlt        ; Check for ALT keys
  133.     CMPNE    R2,#RAlt
  134.     STREQ    R1,Vector_Alt        ; Save ALT status
  135.  
  136.     MOVS    pc,lr
  137.  
  138. ; This is our insert vector handler. It checks every key code entering
  139. ; the keyboard buffer. If it is "ambiguous" (eg Home or Delete), or it is
  140. ; Alt-ed, then a substitute, unique, buffer code sequence is inserted in
  141. ; its place.
  142.  
  143. Insert_Handler
  144.     STMFD    sp!,{R1-R2,lr}
  145.  
  146.     CMP    R1,#0            ; Only the keyboard buffer
  147.     BNE    Ins_1
  148.  
  149.     LDR    R2,Vector_Recursive    ; Don't run recursively
  150.     CMP    R2,#0
  151.     BNE    Ins_1
  152.  
  153. ;    If ALT is pressed, and it is not modifying a keypad key,
  154. ;    then insert a prefix byte (Alt_Prefix) into the input stream.
  155.  
  156.     LDR    R1,Vector_Alt
  157.     LDR    R2,Vector_Key
  158.  
  159.     CMP    R1,#1        ; Check for an ALT
  160.     BNE    %F1
  161.  
  162. ;    Do not process ALT if the international keyboard is in action
  163.     LDR    R1,Vector_International
  164.     CMP    R1,#1
  165.     BEQ    %F1
  166.  
  167.     MOV    R1,#1            ; Don't intercept the recursive call,
  168.     STR    R1,Vector_Recursive    ; or we'll get in an infinite loop!
  169.  
  170.     MOV    R9,pc            ; Go into USR mode
  171.     ORR    R1,R9,#USR_Mode
  172.     TEQP    R1,#0
  173.     MOVNV    R0,R0
  174.  
  175.     STMFD    sp!,{R0,R2,R9,lr}    ; Insert the prefix into the buffer
  176.     MOV    R0,#Alt_Prefix
  177.     MOV    R1,#0
  178.     MOV    R9,#InsV
  179.     SWI    OS_CallAVector
  180.     LDMFD    sp!,{R0,R2,R9,lr}
  181.  
  182.     TEQP    R9,#0            ; Return to previous mode
  183.     MOVNV    R0,R0
  184.  
  185.     MOV    R1,#0            ; We have finished recursing
  186.     STR    R1,Vector_Recursive
  187.  
  188. ;    Now start checking for specific keys
  189.  
  190. 1    CMP    R2,#PageDown        ; Page Down
  191.     BNE    %F2
  192.     LDR    R1,Vector_Shift        ; Put Shift/Control status
  193.     LDR    R0,Vector_Ctrl        ; in bits 4 and 5 of the new
  194.     ADD    R1,R1,R0,LSL #1        ; code, respectively. This is
  195.     MOV    R1,R1,LSL #4        ; the 'standard' for codes > &80
  196.     ADD    R0,R1,#NewPageDown
  197.     B    Ins_1
  198.  
  199. 2    CMP    R2,#PageUp        ; Page Up
  200.     BNE    %F3
  201.     LDR    R1,Vector_Shift        ; Put Shift/Control status
  202.     LDR    R0,Vector_Ctrl        ; in bits 4 and 5 of the new
  203.     ADD    R1,R1,R0,LSL #1        ; code, respectively. This is
  204.     MOV    R1,R1,LSL #4        ; the 'standard' for codes > &80
  205.     ADD    R0,R1,#NewPageUp
  206.     B    Ins_1
  207.  
  208. 3    CMP    R2,#Delete        ; Delete
  209.     BNE    %F4
  210.     LDR    R1,Vector_Shift        ; Put Shift/Control status
  211.     LDR    R0,Vector_Ctrl        ; in bits 4 and 5 of the new
  212.     ADD    R1,R1,R0,LSL #1        ; code, respectively. This is
  213.     MOV    R1,R1,LSL #4        ; the 'standard' for codes > &80
  214.     ADD    R0,R1,#NewDelete
  215.     B    Ins_1
  216.  
  217. 4    CMP    R2,#Home        ; Home
  218.     BNE    %F5
  219.     LDR    R1,Vector_Shift        ; Put Shift/Control status
  220.     LDR    R0,Vector_Ctrl        ; in bits 4 and 5 of the new
  221.     ADD    R1,R1,R0,LSL #1        ; code, respectively. This is
  222.     MOV    R1,R1,LSL #4        ; the 'standard' for codes > &80
  223.     ADD    R0,R1,#NewHome
  224.     B    Ins_1
  225.  
  226. 5    CMP    R2,#Backspace        ; Backspace
  227.     BNE    %F6
  228.     LDR    R1,Vector_Shift        ; Put Shift/Control status
  229.     LDR    R0,Vector_Ctrl        ; in bits 4 and 5 of the new
  230.     ADD    R1,R1,R0,LSL #1        ; code, respectively. This is
  231.     MOV    R1,R1,LSL #4        ; the 'standard' for codes > &80
  232.     ADD    R0,R1,#NewBackspace
  233.     B    Ins_1
  234.  
  235. 6    CMP    R2,#Return        ; Return
  236.     BNE    %F7
  237.     LDR    R1,Vector_Shift        ; Put Shift/Control status
  238.     LDR    R0,Vector_Ctrl        ; in bits 4 and 5 of the new
  239.     ADD    R1,R1,R0,LSL #1        ; code, respectively. This is
  240.     MOV    R1,R1,LSL #4        ; the 'standard' for codes > &80
  241.     ADD    R0,R1,#NewReturn
  242.     B    Ins_1
  243.  
  244. 7    CMP    R2,#Enter        ; Enter (numeric keypad)
  245.     BNE    %F8
  246.     LDR    R1,Vector_Shift        ; Put Shift/Control status
  247.     LDR    R0,Vector_Ctrl        ; in bits 4 and 5 of the new
  248.     ADD    R1,R1,R0,LSL #1        ; code, respectively. This is
  249.     MOV    R1,R1,LSL #4        ; the 'standard' for codes > &80
  250.     ADD    R0,R1,#NewEnter
  251.     B    Ins_1
  252.  
  253. 8
  254. Ins_1
  255.     LDMFD    sp!,{R1-R2,pc}^
  256.  
  257. ; The following are handler status variables. 
  258. ; The variables are set up based on r12. The appropriate value of r12
  259. ; must be supplied to the vector code to ensure correct working. This is
  260. ; handled in C.Archimedes, where the r12 value passed to OS_Claim is set
  261. ; to point to a suitable area of memory.
  262.  
  263.             ^    0,r12
  264. Vector_Recursive    #    4    ; Module has been entered recursively
  265. Vector_Key        #    4    ; Last key pressed
  266. Vector_Shift        #    4    ; Shift key status
  267. Vector_Ctrl        #    4    ; Control key status
  268. Vector_Alt        #    4    ; ALT key status
  269. Vector_International    #    4    ; International Keboard present
  270.  
  271.     END
  272.